// 压型 配料记录表
<template>
  <div class="container">
    <pressed-content
      :form="tableList"
      :operaList="operaList"
      :tableList="tableList"
      :tableData="tableData"
      :res="res"
      :kind="kind"
      :search="search"
      :total_count="total_count"
      @getData="getData"
      @deleteData="deleteData"
      @addData="addData"
      @editData="editData"
    >
      <!-- <template slot="navBar">
        <el-input v-model="search" placeholder="请输入关键字">
          <el-button slot="append" icon="el-icon-search" />
        </el-input>
      </template> -->
    </pressed-content>
  </div>
</template>

<script>
import { GetIngredients, Deleteforming } from '@/api/forming.js'
import '@/mock/default.js'
import { tableMix } from '@/mixin/tableMix.js'
import { qualityRequirementOperaList as operaList } from '@/assets/staticData/operaList/graphiting.js'
import { ingredientsTableList as tableList } from '@/assets/staticData/tableList/forming.js'
export default {
  name: '',
  components: {},
  props: {},
  mixins: [tableMix], // 一些公用的属性方法可以放在mixin里面,各个组件互不影响
  data () {
    return {}
  },
  computed: {},
  watch: {},
  beforeCreate () {
    // sessionStorage.setItem('activeName', 'qualityRequire')
  },
  created () {
    this.kind = 'ingredients'
    this.getData({
      page: 1,
      per_page: 10
    })
  },
  mounted () { },
  methods: {
    addData (data) {
      this.$axios.get('http://127.0.0.1:7002/addRes')
        .then(res => {
          this.res = res.data
        })
    },
    editData (_id, data) {
      this.$axios.get('http://127.0.0.1:7002/editRes')
        .then(res => {
          // console.log(res)
          this.res = res.data
        })
    },
    getData (data) {
      this.operaList = operaList
      this.tableList = tableList
      GetIngredients(data)
        .then(res => {
          if (res.data.data.results === null) {
            this.tableData = []
          } else {
            // 当int类型和float类型传入空值时 会传给后端NaN 再传给前端就是0 通过处理将0转为''
            // 这显然不合理 不过目前只能这样处理 后期一定要改动
            for (let i = 0; i < res.data.data.results.length; i++) {
              for (let j = 0; j < tableList.length; j++) {
                if (res.data.data.results[i][tableList[j].prop] === 0) {
                // console.log(res.data.data.results[i][tableList[j].prop])
                  res.data.data.results[i][tableList[j].prop] = ''
                }
              // console.log(tableList[j].prop)
              }
            }
            this.tableData = res.data.data.results.reverse()
          }
          this.total_count = res.data.data.total_count
        })
    },
    deleteData (data, params) {
      Deleteforming({
        _id: data,
        collection: 'ingredientrecord'
      }).then(res => {
        this.res = res
        this.getData(params)
      })
    }
  }
}
</script>

<style scoped lang="">
</style>
